<?

JCAT_Package::ImportClass('JCAT_ViewGtk',JCAT::PACKAGE_MVCGTK) ;

class UICtrlBaseInfoView extends JCAT_ViewGtk implements JCAT_IViewForm
{
	/**
	 * 控件基本信息
	 * 
	 * @access	public
	 * @param	$aParent=null	JCAT_ViewGtk		拥有此视图的对象
	 * @param	$aUI=null		JCAT_UIGtkGlade		模版引擎
	 * @return	array
	 */
	public function UICtrlBaseInfoView( JCAT_IViewContainer $aParent, JCAT_UIGtkGlade $aUI=null )
	{
		$this->JCAT_ViewGtk('UICtrlBaseInfoView','UICtrlBaseInfoView','BoxUICtrlBaseInfo',$aParent,$aUI) ;
		
		
		// 创建 并 初始化 UICtrl ---------------------------

		$aUICtrl = new JCAT_UIGtkCtrlSelect('UICtrlKind',JCAT_Language::Sentence('栏位类型'),'SelUICtrlKind') ;
		$this->AddUICtrl($aUICtrl) ;
		
		
		$aUICtrl = new JCAT_UIGtkCtrlSText('UICtrlName',JCAT_Language::Sentence('栏位名'),'EntUICtrlName') ;
		$this->AddUICtrl($aUICtrl) ;
		$aUICtrl->AddVerifier(JCAT_Flyweight::GetGlobalInstance('JCAT_UICtrlLengthVerifier',4,-1,false)) ;
		
		$aUICtrl = new JCAT_UIGtkCtrlSText('UICtrlUIName',JCAT_Language::Sentence('UI名称'),'EntUICtrlUIName') ;
		$this->AddUICtrl($aUICtrl) ;
		$aUICtrl->AddVerifier(JCAT_Flyweight::GetGlobalInstance('JCAT_UICtrlLengthVerifier',-1,-1,false)) ;
		
		$aUICtrl = new JCAT_UIGtkCtrlSelect('UICtrlImplementType',JCAT_Language::Sentence('实现方式'),'SelUICtrlImplementType') ;
		$aUICtrl->AddVerifier(JCAT_Flyweight::GetGlobalInstance('JCAT_UICtrlLengthVerifier',-1,-1,false)) ;
		$this->AddUICtrl($aUICtrl) ;
		$this->SetImplementType(UICtrlDocBase::IMPTYPE_INSTANTIATION|UICtrlDocBase::IMPTYPE_DERIVATION) ;

		$aUICtrl = new JCAT_UIGtkCtrlFSChooser('UICtrlClassPath',JCAT_Language::Sentence('文件路径')) ;
		$aUICtrl->SetAction(Gtk::FILE_CHOOSER_ACTION_SAVE) ;
		$this->AddUICtrl($aUICtrl) ;
		$aUICtrl->AddVerifier(JCAT_Flyweight::GetGlobalInstance('JCAT_UICtrlLengthVerifier',-1,-1,false)) ;
		
		// 设置数据交换
		$aDataExchanger = $this->GetDataExchanger() ;
		$aDataExchanger->LinkUICtrlToDocumentData('UICtrlKind','UICtrlKind') ;
		$aDataExchanger->LinkUICtrlToDocumentData('UICtrlName','UICtrlName') ;
		$aDataExchanger->LinkUICtrlToDocumentData('UICtrlUIName','UICtrlUIName') ;
		$aDataExchanger->LinkUICtrlToDocumentData('UICtrlImplementType','UICtrlImplementType') ;
		$aDataExchanger->LinkUICtrlToDocumentData('UICtrlClassPath','UICtrlClassPath') ;
	}
	
	
	/**
	 * 设置可用的 实现方式
	 * 
	 * @access	public
	 * @param	$nTypes			int			what's this
	 * @param	$nSelected		int			what's this
	 * @return	void
	 */
	public function SetImplementType( $nTypes, $nSelected=0 )
	{
		$aUICtrlImplementType = $this->GetUICtrl('UICtrlImplementType') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aUICtrlImplementType,'JCAT_IUIGtkCtrl') ;

		// 清除
		$aUICtrlImplementType->ClearOptions() ;
		
		// 设置 选项
		if( $nTypes&UICtrlDocBase::IMPTYPE_INSTANTIATION )
			$aUICtrlImplementType->AddOption(JCAT_Language::Sentence('实例化'),UICtrlDocBase::IMPTYPE_INSTANTIATION,($nSelected==UICtrlDocBase::IMPTYPE_INSTANTIATION)) ;
		if( $nTypes&UICtrlDocBase::IMPTYPE_DERIVATION )
			$aUICtrlImplementType->AddOption(JCAT_Language::Sentence('派生子类'),UICtrlDocBase::IMPTYPE_DERIVATION,($nSelected==UICtrlDocBase::IMPTYPE_DERIVATION)) ;
	}
	
	/**
	 * what's this
	 * 
	 * @access	public
	 * @param 	$wndEditable	GtkEditable
	 * @return	array
	 */
	public function OnUICtrlNameChanging(GtkEditable $wndEditable)
	{
		$this->AutoSetDocPath() ;
	}


	/**
	 * what's this
	 * 
	 * @access	public
	 * @return	void
	 */
	public function OnImplementTypeChanged( GtkComboBox $wndComboBox )
	{
		$this->AutoSetDocPath() ; 
	}
	
	public function AutoSetDocPath()
	{
		// 控件名称
		$aUICtrlName = $this->GetUICtrl('UICtrlName') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aUICtrlName,'JCAT_IUIFormCtrl') ;
		$sUICtrlName = $aUICtrlName->GetExchangeData() ;
		if(!trim($sUICtrlName))
			return ;

		// 路径控件
		$aUICtrl = $this->GetUICtrl('UICtrlClassPath') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aUICtrl,'JCAT_UIGtkCtrlFSChooser') ;

		// 当前目录
		$arrOldPaths = $aUICtrl->GetExchangeData() ;
		if( empty($arrOldPaths) )
			return ;
		$sOldPath = $arrOldPaths[0] ;

		if( is_dir($sOldPath) )
			$sDir = JCAT_Global::TidyPath($sOldPath) ;
		else
			$sDir = JCAT_Global::TidyPath(dirname($sOldPath)) ;

		// 控件名称已经清空
		if( empty($sUICtrlName) )
		{
			$aUICtrl->SetPath($sDir) ;
		}
		
		// 新名称
		else
		{
			// 实现方式
			$aUICtrlImplementType = $this->GetUICtrl('UICtrlImplementType') ;
			JCAT_ASSERT::ASSERT_INSTANCE($aUICtrlImplementType,'JCAT_IUIFormCtrl') ;
			
			switch($aUICtrlImplementType->GetExchangeData())
			{
				// 实例化
				case UICtrlDocBase::IMPTYPE_INSTANTIATION :
					$sNewPath = "{$sDir}instance.{$sUICtrlName}.php" ;
					break ;

				// 派生化
				case UICtrlDocBase::IMPTYPE_DERIVATION :
					$sNewPath = "{$sDir}class.{$sUICtrlName}.php" ;
					break ;

				default:
					// JCAT_ASSERT::ASSERT_(0,'!?') ;
					return ;
			} 
			$aUICtrl->SetPath($sNewPath) ;
		}
		
		
	}


}

JCAT_Package::ImportInterface('JCAT_IViewForm',JCAT::PACKAGE_MVC) ;

?>